/*
 * ﻿Copyright (C) 2009-2013 NewMain Softech
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
package com.newmainsoftech.gwetons.client.logging;

import com.newmainsoftech.gwetons.shared.logging.LoggerWrap;
import com.newmainsoftech.gwetons.shared.logging.LoggerWrapAdapterTemplate;

public abstract class JsniLoggerWrapAdapterTemplate extends LoggerWrapAdapterTemplate {
	/* Synchronization over jsniLoggerWrapFactory member field is not necessary since 
	 * JavaScript is single thread environment.
	 */
	private JsniLoggerWrapFactory jsniLoggerWrapFactory;
		protected JsniLoggerWrapFactory getJsniLoggerWrapFactory() {
			return jsniLoggerWrapFactory;
		}
		protected void setJsniLoggerWrapFactory(
				JsniLoggerWrapFactory jsniLoggerWrapFactory) {
			
			this.jsniLoggerWrapFactory = jsniLoggerWrapFactory;
			setLoggerWrapFactory( jsniLoggerWrapFactory);
		}
	
	private JsniLoggerWrap jsniLoggerWrap;
		protected JsniLoggerWrap getJsniLoggerWrap() {
			if ( jsniLoggerWrap == null) {
				setJsniLoggerWrap( 
						JsniLoggerWrapFactoryImpl.getJsniLoggerWrap( 
								null, 
								getLoggerWrap(), 
								getNameForLogging(), 
								getJsniLoggerWrapFactory()
								)
						);
			}
			return jsniLoggerWrap;
		}
		protected void setJsniLoggerWrap( JsniLoggerWrap jsniLoggerWrap) {
			this.jsniLoggerWrap = jsniLoggerWrap;
		}
	
	@Override
	protected void setLoggerWrap( LoggerWrap loggerWrap) {
		super.setLoggerWrap( loggerWrap);
		setJsniLoggerWrap( null);
	}
}
